class Solution
{
public:
    int getSum(int a, int b)
    {
        // 整数本身就是补码存储的，忽略符号直接相加

        int result = bitOperationSum(a, b);

        return result;
    }

    // 连带符号位且忽略最高位进位的加法
    int bitOperationSum(int _a, int _b)
    {
        unsigned a = *reinterpret_cast<unsigned int *>(&_a);
        unsigned b = *reinterpret_cast<unsigned int *>(&_b);

        bool ai = false;
        bool bi = false;
        bool carry = false;

        unsigned long long reversedResult = 1;
        while (a || b || carry)
        {
            ai = a & 1;
            bi = b & 1;
            a = a >> 1;
            b = b >> 1;
            reversedResult = reversedResult << 1;
            reversedResult |= ai ^ bi ^ carry;
            carry = (ai && bi) || (ai && carry) || (bi && carry);
        }

        unsigned long long result = 0;
        while (reversedResult > 1)
        {
            result = result << 1;
            result |= reversedResult & 1;
            reversedResult = reversedResult >> 1;
        }
        return result & 0xFFFF'FFFFLL;
    }
};